
// import { sysUserAddAPI, sysUserDelAPI, sysUserDetailAPI, sysUserEditAPI } from "@/apis";
import FormItems from "@/components/FormItems";
import { App, Breadcrumb, Button, Card, Col, Form, Row } from "antd";
import { useEffect } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
const labels = [
  {
    title: '用户名',
    dataIndex: 'USERNAME'
  },
  {
    title: '昵 称',
    dataIndex: 'NICKNAME'
  },
  {
    title: '密 码',
    dataIndex: 'PASSWORD'
  },
  {
    title: '',
    dataIndex: 'tip',
    tips: true
  },
  {
    title: '账户状态',
    dataIndex: 'STATUS',
    isRadio: true,
    options: [
      {
        label: '正常',
        value: 1,
      },
      {
        label: '锁定',
        value: 2,
      }
    ]
  },
]
export default function UserControlNew() {
  const navigate = useNavigate()
  const [params] = useSearchParams()
  const id = params.get('id')
  const [form] = Form.useForm()
  const { message } = App.useApp()
  const onFinish = (values) => {
    // id ? sysUserEditAPI({
    //   id,
    //   data: values
    // }).then(res => {
    //   message.open({
    //     type: res.code === 200 ? 'success' : 'error',
    //     content: res.message
    //   })
    //   if (res.code === 200) {
    //     navigate(-1)
    //   }
    // }) : sysUserAddAPI({
    //   ...values,
    //   PASSWORD: '1'
    // }).then(res => {
    //   message.open({
    //     type: res.code === 200 ? 'success' : 'error',
    //     content: res.message
    //   })
    //   if (res.code === 200) {
    //     navigate(-1)
    //   }
    // })
  }
  useEffect(() => {
    // function getData() {
    //   sysUserDetailAPI(id).then(res => {
    //     if (res.code === 200) {
    //       form.setFieldsValue(res.data)
    //     }
    //   })
    // }
    // form.setFieldsValue({
    //   USERNAME: '',
    //   PASSWORD: '',
    //   NICKNAME:'',
    //   STATUS: 1
    // })
  }, [])
  const handleDel = () => {
    // sysUserDelAPI({id}).then(res => {
    //   message.open({
    //     type: res.code === 200 ? 'success' : 'error',
    //     content: res.message
    //   })
    //   if (res.code === 200) {
    //     navigate(-1)
    //   }
    // })
  }
  return (
    <div>
      <h2 className="headline">{id ? '编辑数据' : '新建数据'}</h2>
      <Card>
        <Form layout="vertical" form={form} onFinish={onFinish} style={{
          maxWidth: 600,
          margin: 'auto'
        }}>
          <Row gutter='24'>
            {labels.map(item => <Col span={24} key={item.dataIndex}>
              {id ? (!item.tips && <FormItems item={item}></FormItems>) : (item.tips ? <p style={{
                margin: 0,
                background: '#eaf5ff',
                padding: '3px 5px',
                borderRadius: '3px',
                color: '#0077fa',
                marginBottom: 24
              }}>注：默认密码为1</p> : (item.dataIndex !== 'PASSWORD' && <FormItems item={item}></FormItems>)
              )}
            </Col>)}
          </Row>
          <Form.Item style={{ textAlign: 'center' }}>
            <Button type="primary" size="large" htmlType="submit">
              保 存
            </Button>
            {id && <Button type="primary" size="large" onClick={handleDel} danger>删除</Button>}
          </Form.Item>
        </Form>
      </Card>
    </div >
  )
}
